home *** CD-ROM | disk | FTP | other *** search
/ bioinformatics.org / bioinformatics.org_software.tar / www.bioinformatics.org / download / ecell2 / ecell220setup.exe / {app} / standard / SRCJ / ECell2Interface.java < prev    next >
Text File  |  2002-05-13  |  4KB  |  201 lines

  1. /**
  2.  * title:     ECell2Interface class (ECell2Interface.java)<p>
  3.  * description  : superclass for ECell2 interface windows <p>
  4.  * Copyright (C) 1996-2001 Keio University <p>
  5.  * Copyright (C) 1998-2001 Japan Science and Technology Corporation (JST)<p>
  6.  *               GNU General Public Licence <p>
  7.  * Division:     Mitui Knowledge Industry Co. Ltd. Bioscience division <p>
  8.  * Version :     $Id: ECell2Interface.java,v 1.3 2002/05/13 00:23:04 ota Exp $ <p>
  9.  */
  10.  
  11. package ecell;
  12.  
  13. import java.awt.event.*;
  14. import javax.swing.JFrame;
  15. import java.awt.*;
  16.  
  17.  
  18.  
  19. abstract class ECell2Interface extends JFrame implements ActionListener, AccessListener
  20. {
  21.     /**
  22.      * instance of MainWindow
  23.      */
  24.     public MainWindow window = null;
  25.     
  26.     private boolean bRunning = false;
  27.     
  28.     
  29.     public static Rectangle geometry = null;
  30.     
  31.     public static Dimension dimScreen = null;
  32.     
  33.     public static String name = null;
  34.     
  35.     
  36.     /**
  37.      * Constructor
  38.      * @param window MainWindow
  39.      */
  40.     ECell2Interface( MainWindow window )
  41.     {
  42.         this.window = window;
  43.         if( ECell2Interface.dimScreen == null )
  44.         {
  45.             ECell2Interface.dimScreen = Toolkit.getDefaultToolkit().getScreenSize();
  46.         }
  47.     }
  48.     
  49.     /**
  50.      * initialize window components
  51.      */
  52.     abstract protected void jbInit();
  53.     
  54.     /**
  55.      * invoke when window has closed
  56.      */
  57.     abstract protected void exit_actionPerformed();
  58.     
  59.     /**
  60.      * event listener for update self
  61.      * @param win MainWindow
  62.      */
  63.     abstract public void accessJni( MainWindow win );
  64.     
  65.     /**
  66.      * event listener for ActionListener
  67.      * @param e ActionEvent
  68.      */
  69.     abstract public void actionPerformed( ActionEvent e );
  70.     
  71.     /**
  72.      * confirming exit when the window is closed.
  73.      * @return boolean
  74.      */
  75.     protected boolean confirmExit()
  76.     {
  77.         return true;
  78.     }
  79.     
  80.     /**
  81.      * exit when the window is closed.
  82.      * @param e     WindowEvent
  83.      * @return void
  84.      */
  85.     protected void processWindowEvent( WindowEvent e )
  86.     {
  87.         super.processWindowEvent(e);
  88.  
  89.         if ( e.getID() == WindowEvent.WINDOW_CLOSING )
  90.         {
  91.             if( confirmExit() )
  92.             {
  93.                 exit_actionPerformed();
  94.             }
  95.         }
  96.     }
  97.         
  98.     
  99.     public boolean getRunningFlag()
  100.     {
  101.         return bRunning;
  102.     }
  103.     
  104.     public void setRunningFlag( boolean flag )
  105.     {
  106.         this.bRunning = flag;
  107.     }
  108.     
  109.     
  110.     public static final void setGeometry( Rectangle geo )
  111.     {
  112.         //synchronized( geometry )
  113.         {
  114.             ECell2Interface.geometry = geo;
  115.         }
  116.     }
  117.     
  118.     public static final Rectangle getGeometry()
  119.     {
  120.         Rectangle geo = ECell2Interface.geometry;
  121.         ECell2Interface.geometry = null;
  122.         return geo;
  123.     }
  124.     
  125.     public static final void setInterfaceName( String name )
  126.     {
  127.         ECell2Interface.name = name;
  128.     }
  129.     
  130.     public static final String getInterfaceName()
  131.     {
  132.         String ret = ECell2Interface.name;
  133.         ECell2Interface.name = null;
  134.         return ret;
  135.     }
  136.     
  137.     protected void setSizeAndLocation( Dimension sz, Point pt )
  138.     {
  139.         Rectangle geo = ECell2Interface.getGeometry();
  140.         if( geo != null )
  141.         {
  142.             Dimension screen = ECell2Interface.dimScreen;
  143. //System.out.println( "Screen size:" + screen );
  144.             if( screen.width < geo.width )
  145.             {
  146.                 geo.width = screen.width;
  147.             }
  148.             if( screen.height < geo.height )
  149.             {
  150.                 geo.height = screen.height;
  151.             }
  152.             if( geo.x == Integer.MIN_VALUE )
  153.             {
  154.                 geo.x = screen.width - geo.width;
  155.             }
  156.             else
  157.             {
  158.                 geo.x = (geo.x < 0)?  (screen.width + geo.x) : geo.x;
  159.                 if( screen.width < (geo.x + geo.width) )
  160.                 {
  161.                     geo.x = screen.width - geo.width;
  162.                 }
  163.                 else if( geo.x < 0 )
  164.                 {
  165.                     geo.x = 0;
  166.                 }
  167.             }
  168.             if( geo.y == Integer.MIN_VALUE )
  169.             {
  170.                 geo.y = screen.height - geo.height;
  171.             }
  172.             else
  173.             {
  174.                 geo.y = (geo.y < 0)?  (screen.height + geo.y) : geo.y;
  175.                 if( screen.height < (geo.y + geo.height) )
  176.                 {
  177.                     geo.y = screen.height - geo.height;
  178.                 }
  179.                 else if( geo.y < 0 )
  180.                 {
  181.                     geo.y = 0;
  182.                 }
  183.             }
  184.  
  185. //System.out.println( "size:" + geo.getSize() + "/location:" + geo.getLocation() );
  186.             
  187.             this.setSize( geo.getSize() );
  188.             this.setLocation( geo.getLocation() );
  189.         }
  190.         else
  191.         {
  192.             this.setSize( sz );
  193.             this.setLocation( pt );
  194.         }
  195.         
  196.     }
  197.     
  198.     
  199. }
  200.  
  201.